package ListPractice;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * @author Xiao
 * @date 2021/7/12
 */
public class Test04 {
    /**
     * 需求：
     * 2,定义测试类Test
     * 在main方法中创建三个Car对象，将多个car对象添加到集合
     * 3,测试类中自定义方法show(ArrayList<Car> list,int mile,double price)
     * 在该方法内部显示 里程不能低于mile,并且价格不高于price 的Car信息
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        ArrayList<Car> list = new ArrayList<>();
        Car c1 = new Car("奔驰", 500, 100.0);
        Car c2 = new Car("丰田", 300, 25.0);
        Car c3 = new Car("比亚迪", 200, 8.5);
        list.add(c1);
        list.add(c2);
        list.add(c3);
        System.out.println("欢迎来到阿良二手车查询系统！");
        System.out.println("请输入里程(英里)：");
        int mile = sc.nextInt();
        System.out.println("请输入价格(万元)：");
        double price = sc.nextDouble();
        show(list, mile, price);
    }

    private static void show(ArrayList<Car> list, int mile, double price) {
        System.out.println("您要查询的Car信息如下：");
        int index = -1;
            for (int i = 0; i < list.size(); i++) {
                Car c = list.get(i);
                int m = c.getMile();
                double p = c.getPrice();
                if (m >= mile && p <= price) {
                    String b = c.getBrand();
                    index = i;
//                    System.out.println(b + "\t" + m + "\t\t\t" + p);
                }
            }
        if (index == -1) {
            System.out.println("当前暂无您要查询的车辆。");
            return;
        }
        System.out.println("brand\tmile(英里)\tprice(万元)");
        for (int i = 0; i < list.size(); i++) {
            Car c = list.get(i);
            int m = c.getMile();
            double p = c.getPrice();
            if (m >= mile && p <= price) {
                String b = c.getBrand();
                System.out.println(b + "\t" + m + "\t\t\t" + p);
            }
        }
    }
}
